package com.qf.main.pharmacy.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.qf.main.pharmacy.entity.Pharmacy;
import com.qf.main.pharmacy.entity.UserLoginData;
import com.qf.main.pharmacy.mapper.UserLoginDataMapper;
import com.qf.main.pharmacy.service.UserLoginDataService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.ObjectUtils;

import javax.annotation.Resource;

/**
 * @author chengqiang
 * @Create 2024-03-04-19:01
 * @Description:
 */
@Service
public class UserLoginDataServiceImpl implements UserLoginDataService {
    @Resource
    private UserLoginDataMapper userLoginDataMapper;

    @Transactional
    public Integer  saveUserLoginData(Integer userId){
        QueryWrapper<UserLoginData> qw = new QueryWrapper<>();
        qw.eq(UserLoginData.COL_USER_ID,userId);
        UserLoginData userLoginData = userLoginDataMapper.selectOne(qw);
        if(!ObjectUtils.isEmpty(userLoginData)){
            userLoginDataMapper.delete(qw);
        }
        UserLoginData userLoginData1 = new UserLoginData();
        userLoginData1.setUserId(userId);
        userLoginDataMapper.insert(userLoginData1);
        return 1;
    }



    @Override
    public UserLoginData getUserLoginData(Integer userId) {
        QueryWrapper<UserLoginData> qw = new QueryWrapper<>();
        qw.eq(UserLoginData.COL_USER_ID,userId);

        return userLoginDataMapper.selectOne(qw);
    }
}
